/**
 * 
 */
package org.wicket.jbpm.engine.utils;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author Emmanuel Nollase - emanux created: May 29, 2009 - 8:21:37 PM
 */
public final class AddJbpmUsers {
	
	/**
	 * This method perform checks on duplicate user including in a group.
	 * @param group - user groups
	 * @param users - specific user
	 * @return - unique entry for jbpm users
	 */
	public static String[] addJbpmUsers(Object[] group, Object[] users) {
		// this to make unique users only be added
		final Set<String> jbpmusers = new HashSet<String>();

		if (null != group ) {
			for (int i = 0; i < group.length; i++) {
				jbpmusers.add(group[i].toString());
			}
		}
		if (null != users) {
			for (int i = 0; i < users.length; i++) {
				jbpmusers.add(users[i].toString());
			}
		}
		 // tmp user holder
		String[] usrtmp = new String[jbpmusers.size()];
		int j = 0;
		for (String val : jbpmusers ) {
			usrtmp[j++] = val;
		}

		return usrtmp;
	}

	public static String[] getGroupUsers(Object[] grpUsr) {
		return addJbpmUsers(grpUsr, null);
	}
	
	public static void addUserInList(List<String> src,List<String> dest) {
		for(String s : src){
			dest.add(s);
		}
	}
	
	private AddJbpmUsers() {
	}
}
